package com.copractice.data.dao;

import java.io.Serializable;
import java.util.List;

import com.copractice.data.entity.PersistentObject;

/**
 * Represents generic DAO interface with basic operations
 *
 * @author Dmitry Churbanov (dmitry.churbanov@gmail.com)
 * @version 1.0 03/13/2009
 */
public interface GenericDAO<T extends PersistentObject, ID extends Serializable> {

    /**
     * Finds entity by primary key
     *
     * @param id primary key
     * @return the instance of entity <code>T</code> or <code>null</code> if entity doesn't exists
     */
    T getById(ID id);

    /**
     * Finds all entities of type <code>T</code>
     *
     * @return the result list of all entities
     */
    List<T> findAll();
    
    /**
     * Finds the entities starting from <code>firstResult</code>. The max number of rows which will be
     * retrieved is <code>maxResults</code>.
     * 
     * @param firstResult the number of a first row to retrieve, starting from <tt>0</tt>.
     * @param maxResults the maximum number of rows to retrieve.
     * @return the result list of all entities
     */
    List<T> find(int firstResult, int maxResults);

    /**
     * Saves entity
     *
     * @param entity instance of entity to save
     * @return instance of entity which was found or null if such entity was not found
     */
    void save(T entity);
    
    /**
     * Updates entity
     * 
     * @param entity instance of entity to update
     */
    void update(T entity);
    
    /**
     * Merges entity
     * 
     * @param entity instance of entity to merge
     */
    void merge(T entity);
    
    /**
     * Removes entity
     *
     * @param entity instance of entity to delete
     */
    void delete(T entity);

    /**
     * Deletes entity by its id
     * 
     * @param id entity identifier
     */
    void deleteById(ID id);
    
}
